package com.hmall.filter;
import lombok.Data;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PrintAnyGatewayFilterFactory extends AbstractGatewayFilterFactory<PrintAnyGatewayFilterFactory.Config> {
    @Override
    public GatewayFilter apply(Config config) {
        return (exchange, chain) -> {
            // 获取请求
            ServerHttpRequest request = exchange.getRequest();
            // 编写过滤器逻辑
            System.out.println("过滤器执行了"+config);
            // 放行
            return chain.filter(exchange);
        };
    }
    @Data
    static class Config{
        private String name;
        private String city;
        private String sex;
    }
    @Override
    public List<String> shortcutFieldOrder() {
        return List.of("name","city","sex");
    }
    // 返回当前配置类的类型，也就是内部的Config
    @Override
    public Class<Config> getConfigClass() {
        return Config.class;
    }
}